package com.ruibo.modules.system.repository;

import com.ruibo.modules.system.domain.SysMenu;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

/**
 * (SysMenu)表数据库访问层
 *
 * @author sunfeng
 * @since 2020-04-17 15:01:44
 */
public interface SysMenuRepository extends JpaRepository<SysMenu, Long>, JpaSpecificationExecutor<SysMenu> {

    @Query(value = "\tselect distinct m.perms\n" +
            "\t\tfrom sys_menu m\n" +
            "\t\t\t left join sys_roles_menus rm on m.id = rm.menu_id\n" +
            "\t\t\t left join sys_users_roles ur on rm.role_id = ur.role_id\n" +
            "\t\t\t left join sys_role r on r.id = ur.role_id\n" +
            "\t\twhere m.visible = '0' and r.status = '0' and ur.user_id = ?1", nativeQuery = true)
    Set<String> findPermsSet(Long userId);


    /**
     * 根据角色ID与菜单类型查询菜单
     * @param roleIds roleIDs
     * @param type 类型
     * @return /
     */
    LinkedHashSet<SysMenu> findBySysRoles_IdInAndMenuTypeNotOrderByOrderNumAsc(Set<Long> roleIds, String type);

    /**
     *  根据父Id查询菜单
     * @param parentId
     * @return
     */
    List<SysMenu> findByParentId(Long parentId);


}
